<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<jsp:include page="../common/common.jsp">
	<jsp:param name="title" value="应用查看授权"/>
</jsp:include>
<link rel="stylesheet" href="${_staticPath}/custom/zTree/css/metroStyle/metroStyle.css?v=1" />
<link rel="stylesheet" href="${_staticPath}/custom/zTree/css/metroStyle/metroStyle.custom.css" />

<div class="page-header">
	<h1>
		授权应用列表
	</h1>
</div>

<div class="row">
	<div class="col-xs-12">
		<div class="row">
			<div class="col-xs-12">
				<div>
					<div class="dataTables_wrapper form-inline no-footer">
						<table id="_table" class="table table-striped table-bordered table-hover dataTable no-footer">
						  
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript">
$('.page-content-area').ace_ajax('loadScripts', scripts, function() {
	jQuery(function($) {
		// 列表
		var roleId='${roleId}';
		var appIds=eval('${appIds}');
		var $table = $("#_table").table({
			url : "${_path}/admin/roleApp/list",
			data:{roleId:roleId},
			tools : [
				{text : '授权', clazz : 'btn-success', icon : 'fa fa-user-plus green', permission : '/admin/roleApp/save', handler : function(){
					$table.ajaxEnable(
							{
								url : "${_path}/admin/roleApp/save",
							    data : {roleId:roleId},
							    after : function(){return null;}
							}, 
							true
					);
				}}
			], 
			columns : [
				{field:'id'},
		        {field:'isEnable', hide : true},
		        {field:'name', title:'名称', align:'left'},
		        {field:'code', title:'编码', align:'left', mobileHide : true},
		        {field:'sort', title:'排序', mobileHide : true},
		        {field:'isEnableStr', title:'是否启用', replace : function (d){
			        if(d.isEnable)
			        	return "<span class='label label-sm label-success'>" + d.isEnableStr + 	"</span>";
		        	else
		        		return "<span class='label label-sm label-warning'>" + d.isEnableStr + "</span>";
		        }},
		        {field:'createTime', title:'创建时间', mobileHide : true}
			],
			operate : [
				{text : '授权', clazz : 'green', icon : 'fa fa-unlock', permission : '/admin/roleApp/save', handler : function(){
					$table.ajaxEnable(
							{
								url : "${_path}/admin/roleApp/save",
							    data : {roleId:roleId},
							    after : function(){return null;}
							}, 
							true
					);
				}}
			], 
			after : function(){
				// 权限处理
				$.permission();
			}
		});
		
		//初始化表格复选框
	    for(var i=0;i<appIds.length;i++){
			$("#_table > tbody > tr").each(
					function(){
						var trId=$(this).find("td:nth-child(2)").text();
						if(parseInt(trId)==appIds[i]){
							$(this).find("td input[type=checkbox]").prop('checked', true);
						} 
					}
			);
		}
		$("#_table tr").find("td:nth-child(2),th:nth-child(2)").css("display","none");
		// 搜索
		$(".search-data").keyup(function () { 
			$table.search();
		});
	});
});
	
</script>
